<!--
  组件名称：切换nav
  -->
<template>
  <div class="s-nav" :class="[`s-nav-${size}`]">
    <div class="s-nav-item" :class="{ active: curNav === item.code }" v-for="item in list" :key="item.code" @click="handleClick(item)">{{ item.name }}</div>
  </div>
</template>
<script>
export default {
  name: 'SNav',
  props: {
    list: {
      type: Array,
      default: () => []
    },
    value: {
      type: [Number, String],
      default: ''
    },
    size: String
  },
  data () {
    return {
      curNav: ''
    }
  },
  methods: {
    handleClick (item) {
      this.$emit('input', item.code)
      this.$emit('click', item)
      this.$emit('change', item.code)
    }
  },
  watch: {
    value: {
      immediate: true,
      handler (newVal) {
        this.curNav = newVal
      }
    }
  }
}
</script>
<style lang="scss" scoped>
  .s-nav {
    color: $--color-primary;
    font-size: 0;
    display: inline-block;
    .s-nav-item {
      font-size: 16px;
      display: inline-block;
      vertical-align: middle;
      padding: 1px 10px;
      background-color: #223447;
      border: 1px solid #2A7A72;
      cursor: pointer;
      &:not(first-child) {
        margin-left: -1px;
      }
      &.active {
        color: #FFF;
        background-color: #2A7A72;
      }
    }
  }
  .s-nav-fact {
    .s-nav-item {
      padding: 1px 10px;
      font-size: 12px;
    }
  }
  .s-nav-mini {
    .s-nav-item {
      padding: 1px 4px;
      font-size: 12px;
    }
  }
</style>
